<?php
include_once("../../includes/config.inc.php");
check_login();
$suserSession=get_suser();
$customer_id=$suserSession['id'];
$replyModel  = new Model_AutoReply();

if($_POST['save']=='1'){
	$data = array();
	$data['customer_id']   = $customer_id;
	$data['type_id']       = '2';
	$data['is_keyword']    = (int)$_POST['is_keyword'];
	$data['reply_content'] = $data['is_keyword'] ? '' : str_inmysql($_POST['reply_content']);
	$data['reply_keyword'] = $data['is_keyword'] ? str_inmysql($_POST['reply_keyword']) : '';
    $data['state']         = (int)$_POST['state'];
    
	if((int)$_POST['id']>0){
		$gxid=(int)$_POST['id'];
		$replyModel->row_update($data," id='{$gxid}' and type_id='2' and customer_id='{$customer_id}' ");
	}else{
		$replyModel->insert($data);
	}
	die('success');
}

$replyRow   = $replyModel->findByCustomerId($customer_id,'2');
$smarty->assign('replyRow',$replyRow);

//敏感词
$row=array();
$arr = D('wx_sense')->dataArr();
foreach($arr as $k=>$v){
    if($v['word']) $row[]=$v['word'];
}
$senseRow = $row ? json_encode($row) : '';
$smarty->assign('senseRow',$senseRow);

$smarty->setTpl('info/templates/auto_reply.html')->display();